<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header(${dept.deptName}+'居民户籍信息')" />
    <style>
        /*.table {table-layout: fixed}*/
    </style>
</head>
<body>
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="xaingForm">
                <input type="hidden" name="xiangId" th:if="${xiangId != null}" th:value="${xiangId}">
                <div class="select-list">
                    <ul>
                        <li class="col-md-4">
                            <input type="hidden" name="id" th:value="${areaInfo?.id}">
                            <input type="hidden" name="areaId" th:value="${areaInfo?.areaId}">
                            乡镇负责人：<input typ="text" name="leader" th:value="${areaInfo?.leader}">
                        </li>
                        <li class="col-md-4">
                            数据录入人：<input typ="text" name="enteredBy" th:value="${areaInfo?.enteredBy}">
                        </li>
                        <li class="col-md-2">
                            <button type="button" class="btn btn-sm btn-danger" onclick="submitHandler()">确认</button>
                        </li>
                    </ul >
                    <ul class="col-md-10">
                        <li class="col-md-4" th:text="本乡共有 + ${alarmCount} + 户没有安装一氧化碳报警器"></li>
                        <li th:if="${xiangId == null}"><a th:text="查看详情" onclick="$.modal.open('详情','detail?page=alarm');"></a></li>
                        <li th:if="${xiangId != null}"><a th:text="查看详情" th:onclick="|$.modal.open('详情','detail?page=alarm&xiangId=${xiangId}');|"></a></li>
                        <li class="col-md-4" th:text="本乡共有 + ${noteCount} + 户发放明白纸"></li>
                        <li th:if="${xiangId == null}"><a th:text="查看详情" onclick="$.modal.open('详情','detail?page=note');"></a></li>
                        <li th:if="${xiangId != null}"><a th:text="查看详情" th:onclick="|$.modal.open('详情','detail?page=note&xiangId=${xiangId}');|"></a></li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-bordered">
            <form id="searchForm">
            <div class="btn-group-sm">
                <a class="btn btn-primary" onclick="$.table.exportExcel('searchForm')">
                    <i th:text="下载表格"  class="fa fa-download"></i>
                </a>
                <a class="btn btn-warning" id="contentFileUpload" onclick="reportData()">
                    <i th:text="上报数据" class="fa fa-upload"></i>
                </a>
                <input type="hidden" name="contentFile" id="contentFile">
                <label class="col-md-offset-1" th:text="总购洁净煤：+ ${totalAmount==null ? '0' : totalAmount}+吨"></label>
            </div>
            </form>
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
function submitHandler() {
    if ($.validate.form()) {
        var config = {
            url: "/jjm/areaInfo/edit",
            type: "post",
            dataType: "json",
            data: $('#xaingForm').serialize(),
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
                $.modal.disable();
            },
            success: function(result) {
                $.modal.close();
                if(result.code == 0){
                    $.modal.msgSuccess(result.msg);
                }else{
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            }
        };
        $.ajax(config)
    }
}
function reportData() {
    $.modal.loading("正在处理中，请稍后...");
   $.ajax({
        type : "get",
        contentType: "application/json;charset=UTF-8",
        url : prefix + "/reportData",
        dataType:'json',
        beforeSend: function () {
            $.modal.loading("正在处理中，请稍后...");
            $.modal.disable();
        },
        success : function(result) {
            if(result.code == 0){
                $.modal.msgSuccess('上报成功');
            }else{
                $.modal.alertError(result.msg);
            }
            $.modal.closeLoading();
        },
        //请求失败，包含具体的错误信息
        error : function(e){

            $.modal.alertError('上报失败，请重试');
            $.modal.closeLoading();
        }
    });
}

var prefix = ctx + "jjm/xiang";
var xiangId = [[${xiangId}]];
var exportUrl = prefix + "/export";
if(xiangId){
    exportUrl = exportUrl+"?townId="+xiangId;
}
$(function(){
    var options = {
        url :prefix+"/infoTable",
        exportUrl: exportUrl,
        modalName: "居民户籍信息",
        showSearch: false,
        showRefresh: false,
        showToggle: false,
        showColumns: false,
        columns:[
            [{
                field: 'townId',
                title: '编号',
                rowspan : 2,
                align: "center",
                valign: "middle"
            }, {
                field: 'townName',
                title: '乡镇',
                rowspan : 2,
                align: "center",
                valign: "middle"
            }, {
                field: 'accurateNum',
                title: titleValue('精准确村<br>确户总户数'),
                rowspan : 2,
                align: "center",
                valign: "middle"
            }, {
                field: 'householdsNum',
                title: titleValue('常住人<br>口户数'),
                rowspan : 2,
                align: "center",
                valign: "middle"
            }, {
                field: 'cleanCoalNum',
                title: titleValue('洁净煤取<br>暖户数'),
                rowspan : 2,
                align: "center",
                valign: "middle"
            }, {
                field: 'notCleanCoalNum',
                title: titleValue('洁净煤<br>未入户数'),
                rowspan : 2,
                align: "center",
                valign: "middle"
            }, {
                field: 'otherWarmNum',
                title: titleValue('采用其他方<br>式取暖户数'),
                rowspan : 2,
                align: "center",
                valign: "middle"
            }, {
                field: 'notWarmNum',
                title: titleValue('冬季不<br>取暖户数'),
                rowspan : 2,
                align: "center",
                valign: "middle"
            },{
                field: 'biomassWarmNum',
                title: titleValue('生物质<br>取暖户数'),
                rowspan : 2,
                align: "center",
                valign: "middle"
            }, {
                field: '',
                title: '乡镇',
                align: "center",
                colspan : 2,
                valign: "middle"
            }, {
                field: '',
                title: '村',
                align: 'center',
                colspan : 2,
                valign: "middle"
            },{
                field: 'totalBuyNum',
                title: titleValue('总购洁<br>净煤数(吨)'),
                rowspan : 2,
                align: "center",
                valign: "middle"
            },{
                title: '操作',
                align: 'center',
                rowspan : 2,
                valign: "middle",
                formatter: function(value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.modal.openTab(\''+row.townName+'居民户籍信息\',\'/jjm/xiang/info?xiangId=' + row.townId + '\')"><i class="fa fa-edit"></i>查看详情</a> ');
                    return actions.join('');
                }
            }],[
                {
                    field: 'townBlNum',
                    title: '乡镇包联人数',
                    rowspan : 1,
                    align: "center",
                    valign: "middle"
                },
                {
                    field: 'townBlVillageNum',
                    title: '包联村数',
                    rowspan : 1,
                    align: "center",
                    valign: "middle"
                },
                {
                    field: 'villageBlNum',
                    title: titleValue('村级包<br>联人数'),
                    rowspan : 1,
                    align: "center",
                    valign: "middle"
                }, {
                    field: 'villageBlHouseNum',
                    title: titleValue('包联<br>户数'),
                    align: "center",
                    valign: "middle"
                }
            ]]
    };
    $.table.init(options);
});


</script>
</body>
</html>